package com.kingsoft.labs.tangram.services;

import com.kingsoft.labs.tangram.domain.Result;

public interface Service {
	public boolean start();
	public boolean stop();
	
	public static class ServiceResult extends Result {
		public final static int RC_ALLSUCCESS	= 0x0;
		public final static int RC_FAILED		= 0x1;
		public final static int RC_UNFINISHED	= 0x2;
		public final static int RC_NOT_FOUND		= 0x4;
		
		public void setFinished(boolean isFinished) {
			if (isFinished) {
				// clear unfinished flag
				returnCode &= ~RC_UNFINISHED;
			} else {
				// set unfinished flag
				returnCode |= RC_UNFINISHED;
			}
		}
		
		public boolean isFinished() {
			return 0 == (returnCode & RC_UNFINISHED);
		}
		
		public void setSuccessful(boolean isSuccessful) {
			if (isSuccessful) {
				// clear unfinished flag
				returnCode &= ~RC_FAILED;
			} else {
				// set unfinished flag
				returnCode |= RC_FAILED;
			}
		}
		
		public boolean isSuccessful() {
			return 0 == (returnCode & RC_FAILED);
		}
		
	}
}
